package web;


import spring.cloud.tasks.client.Client;
import spring.cloud.tasks.client.item_task_processor.TaskProcessorInfo;
import spring.cloud.tasks.client.item_task_processor.Task;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class serverList {
    public static void main(String[] args) throws Exception {
        HttpServletRequest request = null;
        String machineId = request.getParameter("workerId");
        String baseTaskType = request.getParameter("$taskId");
        String ownSign = request.getParameter("ownSign");
        String ip = request.getParameter("ip");
        String orderStr = request.getParameter("orderStr");
        List<TaskProcessorInfo> schedulerInfoList = null;
        if (machineId != null && machineId.trim().length() > 0) {
            schedulerInfoList = Client.getZooKeeperItemTaskDataManager().getTaskProcessorInfoListByWorkerId(machineId);
        } else {
            schedulerInfoList = Client.getZooKeeperItemTaskDataManager().getProcessorInfoList(baseTaskType, ip, orderStr);
        }

        for (int j = 0; j < schedulerInfoList.size(); j++) {
            String bgColor = "";
            Task task = Client.getZooKeeperItemTaskDataManager().loadTask(schedulerInfoList.get(j).getTaskId());
            if (schedulerInfoList.get(j).getCenterServerTime().getTime() - schedulerInfoList.get(j).getHeartBeatTime().getTime() > task.getJudgeDeadInterval()) {
                bgColor = "BGCOLOR='#A9A9A9'";
            } else if (schedulerInfoList.get(j).getLastFetchDataTime() == null || schedulerInfoList.get(j).getCenterServerTime().getTime() - schedulerInfoList.get(j).getLastFetchDataTime().getTime() > task.getHeartBeatRate() * 20) {
                bgColor = "BGCOLOR='#FF0000'";
            }
            schedulerInfoList.get(j).getTaskId();
            schedulerInfoList.get(j).getIp();

            schedulerInfoList.get(j).getThreadNum();
            schedulerInfoList.get(j).getRegisterTime();
            schedulerInfoList.get(j).getHeartBeatTime();
            schedulerInfoList.get(j).getLastFetchDataTime();
            schedulerInfoList.get(j).getVersion();
            schedulerInfoList.get(j).getNextRunStartTime();

            schedulerInfoList.get(j).getWorkerId();
            schedulerInfoList.get(j).getMark();
        }
    }
}